package com.zhuss.product.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.product.train.UpdateLineStrategyBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.exception.DzcxException;
import com.zhuss.product.db.dao.ext.LineStrategyDao;
import com.zhuss.product.db.entity.LineStrategy;

/**
 * @description: 线路策略修改
 * @author: zhushanshuo
 * @create: Mon Jan 04 09:51:07 CST 2021
 **/
@Component("lineStrategyUpdate")
public class LineStrategyUpdate extends AbstractProcessor<Object, UpdateLineStrategyBo> implements Processor<Object, UpdateLineStrategyBo> {

    @Autowired
    private LineStrategyDao lineStrategyDao;

    @Autowired
	@Qualifier("lineStrategyRead")
	private LineStrategyRead lineStrategyRead;

    /**
     * 校验
     */
    @SuppressWarnings("unused")
	@Override
    public void check(UpdateLineStrategyBo bo) throws DzcxException {
    	// TODO 修改 线路策略 校验， 请补充

    	Long lineStrategyId = bo.getLineStrategyId();
//    	String name = bo.getName();
//    	if (lineStrategyId == null || lineStrategyId <= 0l) {
//    		throw new DzcxException(ExceptionCode.线路策略ID为空);
//    	}
//    	if (name == null || "".equals(name.trim())) {
//    		// throw new DzcxException(ExceptionCode.线路策略name为空);
//    	}
//
//    	List<LineStrategy> list = lineStrategyRead.listNotId(name, lineStrategyId);
//    	if (!list.isEmpty()) {
//    		// throw new DzcxException(ExceptionCode.线路策略name已存在);
//    	}
    }

    /**
     * 操作方法
     */
    @Override
    public Object process(UpdateLineStrategyBo param) {
    	LineStrategy record = new LineStrategy();
    	record.setLineStrategyId(param.getLineStrategyId());
    	record.setLineId(param.getLineId());
    	record.setBoardNo(param.getBoardNo());
    	record.setStartDate(param.getStartDate());
    	record.setEndDate(param.getEndDate());
    	record.setStartTime(param.getStartTime());
    	record.setStrategyType(param.getStrategyType());
    	record.setStatus(param.getStatus());
    	record.setSort(param.getSort());


    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	lineStrategyDao.updateByPrimaryKeySelective(record);
        return null;
    }

    /**
     * 操作日志
     */
	@Override
	public Object log(UpdateLineStrategyBo param) throws DzcxException {
		OpLog record = new OpLog();
//    	record.setMoudle(MoudleEnum.默认模块请修改.key());
//    	record.setAction(LogActionEnum.线路策略修改.key());
//    	record.setTargetId(param.getLineStrategyId());
//    	record.setTargetName(param.getName());
//    	record.setContent("参数: " + JsonUtil.toJson(param));
//    	record.setReason(param.getExceptionReason());

    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
